package com.xzakota.minesweeper.msg;

import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;

/**
 * 消息基类
 *
 * @author Xzakota
 */
public abstract class BaseMsg implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    public static final String DEFAULT_TAG = BaseMsg.class.getSimpleName();

    public int code;
    public Object data;

    public BaseMsg() {
        code = MsgCode.BASE_UNKNOWN;
    }

    public BaseMsg(Object data) {
        this.data = data;
    }

    public String getTag() {
        return DEFAULT_TAG;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        BaseMsg baseMsg = (BaseMsg) o;
        return code == baseMsg.code && Objects.equals(data, baseMsg.data);
    }

    @Override
    public int hashCode() {
        return Objects.hash(code, data);
    }

    @Override
    public String toString() {
        return "BaseMsg{" +
                "code=" + code +
                ", data=" + data +
                '}';
    }
}
